#include "backendprocessor.h"
#include <QObject>
#include <QTimer>
#include <QDebug>

BackendProcessor::BackendProcessor()
{
    timer.setInterval(500);  // 每500毫秒检查一次
    connect(&timer, &QTimer::timeout, this, &BackendProcessor::processButtonClicks);
    timer.start();
}

void BackendProcessor::processButtonClicks()
{
    ButtonManager* manager = ButtonManager::instance();
    QMap<int, bool> currentStates = manager->getButtonStates();
    for (int buttonId = 1; buttonId <= 10; ++buttonId) {
        if (currentStates[buttonId]) {
            // 这里根据按钮ID执行相应的功能
            qDebug() << "Button" << buttonId << "was clicked in the backend.";
            // 例如，假设这里是执行某个函数
            handleButtonFunction(buttonId);
            // 处理完后重置按钮状态，避免重复处理
            manager->resetButtonStates();
        }
    }
}

void BackendProcessor::handleButtonFunction(int buttonId)
{
    // 这里可以是复杂的业务逻辑，根据按钮ID执行不同操作
    switch (buttonId) {
    case 1:
        // 执行功能1
        break;
    case 2:
        // 执行功能2
        break;
    // 其他按钮的情况...
    default:
        break;
    }
}
